<?php


namespace app\order\admin;


use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;
use app\services\models\Cards as CardsModel;

class Cards extends Admin
{

    /**
     * @return mixed
     * @throws \think\Exception
     */
    public function index(){

        $map        = $this->getMap();
        if (!isAdmin()) {
            $map['agency_id']  = getAgencyId();
        }
        $data       = Db::name('cards')->where($map)->order('id','asc')->paginate();
        return ZBuilder::make('table')
            ->hideCheckbox()
            ->setSearch(['tel','acctname','cardno'])
            ->addColumns([
                ['acctname','姓名'],
           
                ['tel','预留手机号','callback',function($val){return hideMobile($val);}],
                ['cardno','卡号','callback',function($val){return hideMiddle($val); }],
                ['idno','身份证号','callback',function($val){return hideIdNo($val);}],
                ['bank_name','银行名称'],
                //['bill_date','账单日'],
                //['pay_date','最后还款日'],
                ['status','状态',CardsModel::status_text],
                //['ret','返回值'],
                ['created_at','绑定时间','callback',function($val){return substr($val,0,16);}],
                ['right_button','操作']
            ])
            ->addTimeFilter('created_at')
            ->setColumnWidth('acctname,validate,bill_date,pay_date,status', 50)
            ->addRightButton('custom',[
                'title' => '查看详情',
                'icon'  => 'fa fa-fw fa-search',
                'href'  => url('detail',['id'=>'__id__']),
            ])
            ->addFilter(['status'],CardsModel::status_text)
            ->setRowList($data)
            ->setTableName('cards')
            ->setPages($data->render())
            ->fetch();
    }

    public function detail($id = ''){
        $card = CardsModel::get($id);
        return ZBuilder::make('form')
            ->setPageTitle($card['acctname'])
            ->hideBtn('submit')
            ->addFormItems([
               // ['text','cardno','卡号','',$card['cardno']],
                ['textarea','ret','API返回值','',$card['ret']],
               // ['text','cvv2','cvv2','',$card['cvv2']],
            ])
            ->fetch();
    }

}